package com.okbihuo.perm.modules.auth.controller;

import com.github.xiaoymin.knife4j.annotations.ApiSort;
import com.okbihuo.perm.core.tool.api.BaseException;
import com.okbihuo.perm.core.tool.api.R;
import com.okbihuo.perm.modules.auth.UserDetailServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@ApiSort(1)
@RestController
@RequestMapping("auth")
@RequiredArgsConstructor
@Api(value = "用户授权认证", tags = "授权接口")
public class AuthController {

    private final UserDetailServiceImpl userDetailService;


    @ApiOperation(value = "获取当前用户信息")
    @RequestMapping("user/info")
    @PreAuthorize("isAuthenticated()")
    public String getCurrentUserInfo() throws BaseException {
        return R.data(userDetailService.currentInfo()).toJSON();

    }


}
